<template>
  <div id="app">
    <transition :name="transitionName">
      <keep-alive v-if="$route.meta.keepAlive">
        <router-view class="child-view" v-show="visible"></router-view>
      </keep-alive>

      <router-view
        class="child-view"
        v-show="visible"
        v-if="!$route.meta.keepAlive"
      ></router-view>
    </transition>
  </div>
</template>

<script>
export default {
  name: "app",
  data() {
    return {
      transitionName: "van-slide-right",
      visible: true,
      route: "",
    };
  },
  watch: {
    $route(n) {
      if (this.$router.isBack) {
        this.transitionName = "van-slide-left";
      } else {
        this.transitionName = "van-slide-right";
      }

      switch (n.path) {
        case "/home":
          this.$active = 0;

          break;
        case "/trade":
          this.$active = 1;

          break;
        case "/log":
          this.$active = 2;

          break;
        case "/question":
          this.$active = 3;

          break;
        case "/mine":
          this.$active = 4;

          break;

        default:
          break;
      }
    },
  },
};
</script>

<style lang="scss">
html,
body,
#app {
  margin: 0 auto;
  height: 100%;
  font-family: "Avenir", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  position: relative;
}

.child-view {
  position: absolute;
  top: 0;
  width: 100%;
}
</style>
